﻿/*
 * Resuelve el envío y recepción de data XML
 * 
 * Zero
 * 1.0
 *  
 */
 
 import com.dinmax.flash.utilities.communication.XMLCommunicationListener;
 
 class com.dinmax.flash.utilities.communication.XMLCommunication {
	
	private var gateway:String;
	private var listener:XMLCommunicationListener;
	private var sender:XML;
	private var reciver:XML;
		
	public static function newInstance(gateway:String, listener:XMLCommunicationListener):XMLCommunication {
		return new XMLCommunication(gateway, listener);
	}
	
	function XMLCommunication(gateway:String, listener:XMLCommunicationListener){
		
		var root:XMLCommunication = this;
		this.setGateway(gateway);
		this.setListener(listener);
		this.reciver = new XML();
		this.reciver.onLoad = function(success:Boolean):Void{
			if(success){
				root.getListener().finished(this);
			} else {
				root.getListener().error(this);
			}
		}
	};
	
	public function setGateway(gateway:String):Void {
		this.gateway = gateway;
	};
	
	public function getGateway():String {
		return this.gateway;
	};
	
	public function setListener(listener:XMLCommunicationListener):Void {
		this.listener = listener;
	};
	
	public function getListener():XMLCommunicationListener {
		return this.listener;
	};
	
	public function getReciver():XML {
		return this.reciver;
	};
	
	public function send(xml:XML):Void {
		this.sender = xml;
		//trace("---\n"+sender+"\n---");
		sender.sendAndLoad(gateway, reciver)
	};
	
}; // fin de clase